package com.PlantVsZombies.Plants;

import java.awt.Graphics;
import java.io.Serializable;

import javax.swing.ImageIcon;

import com.PlantVsZombies.common.Life;
import com.PlantVsZombies.util.ImageUtil;
import com.PlantVsZombies.util.MusicPlay;
import com.PlantVsZombies.util.MusicUtil;

public class Sun extends Life implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public int x;
	public int y;
	public int life = 15;
	transient MusicPlay mp = new MusicPlay(MusicUtil.COLLECTSUN);
	
	ImageIcon image;
	

	public Sun(int x, int y) {
		this.x = x;
		this.y = y;
		this.image = ImageUtil.sun;
	}

	public void drop() {
		this.y+=5;
	}
	public void drawMe(Graphics g){
		g.drawImage(image.getImage(), x, y, null);
	}
	public int isClicked(int x, int y) {
		if (x > this.x -100 && y > this.y-100  && x < this.x + image.getImage().getWidth(null)+20
				&& y < this.y + image.getImage().getHeight(null)+20) {
			mp.replay();
			return 25;
		}
		return 0;
	}

	@Override
	public int doRun() {
		if (this.y < 400)
			this.drop();
		else
			this.life--;
		if(life<0){
			setLive(false);
			return 0;
		}

		try {
			Thread.sleep(150);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return 1;
	}
}
